package org.apache.nifi.processors.huawei.smn;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.region.Region;
import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
import com.huaweicloud.sdk.smn.v2.SmnClient;
import org.apache.nifi.processor.ProcessContext;

import java.util.List;

import static org.apache.nifi.processors.huawei.common.PropertyDescriptors.*;
import static org.apache.nifi.processors.huawei.smn.PublishSMNMessage.SMN_PROJECT_ID;

public class SMNUtils {

    public static SmnClient createClient(final ProcessContext processContext) {

        final String accessKey = processContext.getProperty(ACCESS_KEY).evaluateAttributeExpressions().getValue();
        final String secretKey = processContext.getProperty(SECRET_KEY).evaluateAttributeExpressions().getValue();
        final String projectId = processContext.getProperty(SMN_PROJECT_ID).evaluateAttributeExpressions().getValue();
        final String region = processContext.getProperty(SMN_REGION).evaluateAttributeExpressions().getValue();

        return SmnClient.newBuilder().withCredential(
                new BasicCredentials().withAk(accessKey).withSk(secretKey).withProjectId(projectId))
                .withRegion(SmnRegion.valueOf(region)).build();
    }

    public static List<Region> getAvailableRegions() {

        return List.of(
                SmnRegion.AF_SOUTH_1,
                SmnRegion.CN_NORTH_4,
                SmnRegion.CN_NORTH_1,
                SmnRegion.CN_EAST_2,
                SmnRegion.CN_EAST_3,
                SmnRegion.CN_SOUTH_1,
                SmnRegion.CN_SOUTHWEST_2,
                SmnRegion.AP_SOUTHEAST_2,
                SmnRegion.AP_SOUTHEAST_1,
                SmnRegion.AP_SOUTHEAST_3,
                SmnRegion.CN_NORTH_2,
                SmnRegion.CN_SOUTH_2,
                SmnRegion.NA_MEXICO_1,
                SmnRegion.LA_NORTH_2,
                SmnRegion.SA_BRAZIL_1,
                SmnRegion.LA_SOUTH_2,
                SmnRegion.CN_NORTH_9
        );
    }
}
